#include "stdio.h"
int getnum(int c)
{
    int num = 0;
   while (c)
   {
    num += c%10;
    c /= 10;
   }
return num;
}
int main()
{
int i;
int j;
int m;
int n;
int num;
int k = 0;
scanf ("%d",&n);
scanf ("%d",&m);
int arr[n];
for (i = 0;i <= 54; i++)
{
  for (j = 1;j <= n; j++)
    {
      num = getnum(j);
      if (num == i)
      {
       arr[k++] = num;
      }
    }
}
    printf ("%d",arr[m-1]); 
    return 0;
}